<template>
    <div>
        <div>
            <el-form :inline="true" :model="formInline" class="demo-form-inline" style="height: 80%;">
                <el-form-item label="采购日期:">
                    <el-date-picker v-model="formInline.sdate" type="date" aria-label="选择日期" style="width: 200px" />
                    <el-date-picker v-model="formInline.edate" type="date" aria-label="选择日期" style="width: 200px" />
                </el-form-item>
                <el-form-item label="羊只类型:">
                    <el-select v-model="formInline.sheeptypeinfo" clearable>
                        <el-option v-for="item in sheeptype" :key="item.Id" :label="item.Name" :value="item.Name" />
                    </el-select>
                </el-form-item>
                <el-form-item label="仓库:">
                    <el-select v-model="formInline.stash" clearable>
                        <el-option v-for="item in StashInfo" :key="item.Id" :label="item.Name" :value="item.Name" />
                    </el-select>
                </el-form-item>
                <el-button type="primary" size="lang" @click="handleShowPurchase">查询</el-button>
                <br>
                <el-form-item label="栋舍:">
                    <el-select v-model="formInline.cottagename" clearable>
                        <el-option v-for="item in Cottage" :key="item.Id" :label="item.Name" :value="item.Name" />
                    </el-select>
                </el-form-item>
                <el-form-item label="批次/耳号:">
                    <el-input v-model="formInline.earbugles">
                    </el-input>
                </el-form-item>
                <el-form-item label="采购员:">
                    <el-select v-model="formInline.buyer" clearable>
                        <el-option v-for="item in StaffList" :key="item.id" :label="item.name" :value="item.name" />
                    </el-select>
                </el-form-item>
                <br>
                <el-form-item label="单据号:">
                    <el-input v-model="formInline.documentnumber">
                    </el-input>
                </el-form-item>
                <el-form-item label="供应商:">
                    <el-select v-model="formInline.supplier">
                        <el-option v-for="item in SupplierList" :key="item.Id" :label="item.Name" :value="item.Name" />
                    </el-select>
                </el-form-item>
            </el-form>
            <div>
                <el-button type="danger" size="large" @click="handleAdd" :icon="Plus">新增</el-button>
                <el-button type="danger" size="large" @click="handleDeleteAll" :icon="Delete">删除</el-button>
                <el-button type="danger" size="large" @click="handleExamine" :icon="Stamp">审核</el-button>
                <el-button type="danger" size="large" @click="handleNewExamine" :icon="Stamp">重新审核</el-button>
            </div>
        </div>
        <div v-if="TagBool">
            <el-tag style="width:1920px;color: black;height: 50px;" type="danger" :iocn="Delete">
                <spna style="font-size: 15px">
                    <Warning style="width: 1em; height: 1em; margin-right: 8px" color="red" />
                    <span style="margin-right: 1800px">已选择 {{ TagCount }} 项</span>
                </spna>
            </el-tag>
        </div>
        <div v-else>
            <el-tag style="width:1920px;color: black;height: 50px;" type="success" :iocn="Delete">
                <spna style="font-size: 15px">
                    <SuccessFilled style="width: 1em; height: 1em; margin-right: 8px" color="green" />
                    <span style="margin-right: 1800px">已选择 {{ TagCount }} 项</span>
                </spna>
            </el-tag>
        </div> <br />
        <el-table ref="multipleTableRef" :data="PurList" style="width: 100%" border
            @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" />
            <el-table-column label="序号" width="120" fixed>
                <template v-slot="scope">
                    <span>{{ scope.$index + (page.pageIndex - 1) * page.pageSize + 1 }}</span>
                </template>
            </el-table-column>
            <el-table-column property="ExamineType" label="审核状态" width="100px">
                <template v-slot="scope">
                    <div v-if="scope.row.ExamineType == false">
                        <el-tag type="success" size="mini">已审核</el-tag>
                    </div>
                    <div v-else>
                        <el-tag type="error" size="mini">未审核</el-tag>
                    </div>
                </template>
            </el-table-column>
            <el-table-column property="DocumentNumber" label="单据号" />
            <el-table-column property="PurDate" label="采购日期" width="200px">
                <template v-slot="scope">
                    <span>{{ scope.row.PurDate ? scope.row.PurDate.replace('T', ' ').substring(0, 10) : null }}</span>
                </template>
            </el-table-column>
            <el-table-column property="AccountingUnit" label="核算单元" width="120px">
            </el-table-column>
            <el-table-column property="PruTytpe" label="类别" width="120px">
            </el-table-column>
            <el-table-column property="Supplier" label="供应商" width="120px">
            </el-table-column>
            <el-table-column property="Earbugles" label="批次/耳号" width="120px">
            </el-table-column>
            <el-table-column property="CottageName" label="栋舍" width="120px">
            </el-table-column>
            <el-table-column property="FieldName" label="转入栏位" width="120px">
            </el-table-column>
            <el-table-column property="PurSex" label="性别" width="120px">
            </el-table-column>
            <el-table-column property="Buyer" label="采购员" width="120px">
            </el-table-column>
            <el-table-column property="Stash" label="仓库" width="120px">
            </el-table-column>
            <el-table-column property="GoodName" label="商品名称" width="120px">
            </el-table-column>
            <el-table-column property="Package" label="标包" width="120px">
            </el-table-column>
            <el-table-column property="QuantityNumber" label="入库数量" width="120px">
            </el-table-column>
            <el-table-column property="AveragePrice" label="只均单价(元)" width="120px">
                <template v-slot="scope">
                    <span>{{ scope.row.AveragePrice.toFixed(2) }}</span>
                </template>
            </el-table-column>
            <el-table-column property="Price" label="金额(元)" width="120px">
                <template v-slot="scope">
                    <span>{{ (scope.row.QuantityNumber * scope.row.AveragePrice).toFixed(2) }}</span>
                </template>
            </el-table-column>
            <el-table-column property="PriceDiscount" label="单位折扣" width="120px">
                <template v-slot="scope">
                    <span>{{ scope.row.PriceDiscount }}</span>
                </template>
            </el-table-column>
            <el-table-column property="PricePay" label="结算金额(元)" width="120px">
                <template v-slot="scope">
                    <span>{{ (scope.row.QuantityNumber * scope.row.AveragePrice *
                        scope.row.PriceDiscount).toFixed(2) }}</span>
                </template>
            </el-table-column>
            <el-table-column property="CreateBy" label="创建人" width="120px">
            </el-table-column>
            <el-table-column property="CreateDate" label="创建时间" width="200px">
                <template v-slot="scope">
                    <span>{{ scope.row.CreateDate ? scope.row.CreateDate.replace('T', ' ').substring(0, 19) : null
                        }}</span>
                </template>
            </el-table-column>
            <el-table-column property="UpdateBy" label="修改人" width="120px">
            </el-table-column>
            <el-table-column property="UpdateDate" label="修改时间" width="200px">
                <template v-slot="scope">
                    <span>{{ scope.row.UpdateDate ? scope.row.UpdateDate.replace('T', ' ').substring(0, 19) : null
                        }}</span>
                </template>
            </el-table-column>
            <el-table-column property="ExamineBy" label="审核人" width="120px">
            </el-table-column>
            <el-table-column property="ExamineDate" label="审核时间" width="200px">
                <template v-slot="scope">
                    <span>{{ scope.row.ExamineDate ? scope.row.ExamineDate.replace('T', ' ').substring(0, 19) : null
                        }}</span>
                </template>
            </el-table-column>
            <el-table-column fixed="right" label="操作" width="120">
                <template v-slot="scope">
                    <div v-if="scope.row.ExamineType == true">
                        <el-button link type="primary" size="default" @click="handleEdit(scope.row.PurId)">
                            编辑
                        </el-button>
                        <el-button link type="primary" size="default"
                            @click="handleDelete(scope.row.PurId)">删除</el-button>
                    </div>
                    <div v-else>
                        <el-button link type="default" size="default">已审核</el-button>
                    </div>
                </template>
            </el-table-column>
        </el-table>
        <table style="text-align: center;">
            <tr>
                <td>
                    <div>
                        <el-pagination v-model:current-page="page.pageIndex" v-model:page-size="page.pageSize"
                            :page-sizes="[1, 15, 30, 45]" :background="true"
                            layout="slot,total, sizes, prev, pager, next, jumper" :total="page.totalCount"
                            @size-change="handleSizeChange" @current-change="handleCurrentChange" />
                    </div>
                </td>
            </tr>
        </table>
        <el-dialog v-model="dialogTableVisible" title="羊只采购-新增" style="width: 85%; height: 80%;"
            :before-close="NewUpdate">
            <!-- {{ purchaseForm }} -->
            <div>
                <el-button type="danger" size="large" @click="AddPurInfo" :icon="SuccessFilled">保存</el-button>
                <br>
            </div>
            <el-form :inline="true" :model="purchaseForm" class="demo-form-inline" style="height: 80%;">
                <el-form-item label="采购员:">
                    <el-select v-model="purchaseForm.Buyer" clearable>
                        <el-option v-for="item in StaffList" :key="item.id" :label="item.name" :value="item.name" />
                    </el-select>
                </el-form-item>
                <el-form-item label="采购日期:">
                    <el-date-picker v-model="purchaseForm.PurDate" type="date" aria-label="选择日期" style="width: 200px" />
                </el-form-item>
                <el-form-item label="羊只类型:">
                    <div v-if="purchaseForm.SheepTypeInfo == '后裔'">
                        <el-select v-model="purchaseForm.SheepTypeInfo" clearable>
                            <el-option v-for="item in sheeptype" :key="item.Id" :label="item.Name" :value="item.Name" />
                        </el-select>
                    </div>
                    <div v-else>
                        <el-select v-model="purchaseForm.SheepTypeInfo" clearable @change="ChangeSex">
                            <el-option v-for="item in sheeptype" :key="item.Id" :label="item.Name" :value="item.Name" />
                        </el-select>
                    </div>
                </el-form-item>
                <br>
                <el-form-item label="核算单元:">
                    <el-select v-model="purchaseForm.AccountingUnit" clearable>
                        <el-option v-for="item in AccountingList" :key="item.Id" :label="item.Name"
                            :value="item.Name" />
                    </el-select>
                </el-form-item>
                <el-form-item label="类别:">
                    <el-text v-model="purchaseForm.PruTytpe">采购单</el-text>
                </el-form-item>
                <el-form-item label="供应商:">
                    <el-select v-model="purchaseForm.Supplier">
                        <el-option v-for="item in SupplierList" :key="item.Id" :label="item.Name" :value="item.Name" />
                    </el-select>
                </el-form-item>
                <el-form-item label="仓库:">
                    <el-select v-model="purchaseForm.Stash" clearable>
                        <el-option v-for="item in StashInfo" :key="item.Id" :label="item.Name" :value="item.Name" />
                    </el-select>
                </el-form-item>
                <br>
                <el-form-item label="摘要:">
                    <el-select v-model="purchaseForm.Digest" clearable>
                        <el-option v-for="item in DigestList" :key="item.Id" :label="item.Name" :value="item.Name" />
                    </el-select>
                </el-form-item>
                <el-form-item label="单据号:">
                    <el-input v-model="purchaseForm.DocumentNumber"></el-input>
                </el-form-item>
            </el-form>
            <el-table :data="rowList" style="width: 100%;" border :scrollbar-always-on="true">
                <el-table-column label="序号" fixed>
                    <template v-slot="scope">
                        <span>{{ scope.$index + (page.pageIndex - 1) * page.pageSize + 1 }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="批次/耳号" prop="Earbugles">
                    <span>
                        <el-input v-model="purchaseForm.Earbugles" style="width: 250px;"></el-input>
                    </span>
                </el-table-column>
                <el-table-column label="栋舍" prop="CottageName">
                    <el-select v-model="purchaseForm.CottageName" style="width: 200px;" @change="GetField">
                        <el-option v-for="item in Cottage" :key="item.Id" :label="item.Name" :value="item.Name" />
                    </el-select>
                </el-table-column>
                <el-table-column label="转入栏位" prop="FieldName">
                    <span>
                        <el-select v-model="purchaseForm.FieldName" style="width: 200px;">
                            <el-option v-for="item in Field" :key="item.Id" :label="item.Name" :value="item.Name" />
                        </el-select>
                    </span>
                </el-table-column>
                <el-table-column label="性别" prop="PurSex">
                    <div v-if="purchaseForm.SheepTypeInfo == '后裔'">
                        <span>
                            <el-radio-group v-model="purchaseForm.PurSex" class="ml-4" style="width: 200px;">
                                <el-radio value="公" size="large">公</el-radio>
                                <el-radio value="母" size="large">母</el-radio>
                            </el-radio-group>
                        </span>
                    </div>
                    <div v-else>
                        <span>
                            <el-radio-group v-model="purchaseForm.PurSex" class="ml-4" style="width: 200px;"
                                @change="ChangeSex1">
                                <el-radio value="公" size="large">公</el-radio>
                                <el-radio value="母" size="large">母</el-radio>
                            </el-radio-group>
                        </span>
                    </div>
                </el-table-column>
                <el-table-column label="商品名称" prop="GoodName">
                    <span>
                        <el-input v-model="purchaseForm.GoodName" style="width: 250px;"></el-input>
                    </span>
                </el-table-column>
                <el-table-column label="标包" prop="Package">
                    <span>
                        <el-input v-model="purchaseForm.Package" style="width: 250px;"></el-input>
                    </span>
                </el-table-column>
                <el-table-column label="计量单位" prop="MeasuringUnit">
                    <span>
                        <el-input v-model="purchaseForm.MeasuringUnit" style="width: 250px;"></el-input>
                    </span>
                </el-table-column>
                <el-table-column label="入库数量" prop="QuantityNumber">
                    <span>
                        <el-input v-model="purchaseForm.QuantityNumber" style="width: 250px;"></el-input>
                    </span>
                </el-table-column>
                <el-table-column label="只均单价(元)" prop="AveragePrice">
                    <span>
                        <el-input v-model="purchaseForm.AveragePrice" style="width: 250px;"></el-input>
                    </span>
                </el-table-column>
                <el-table-column label="单位折扣(元)" prop="PriceDiscount">
                    <span>
                        <el-input v-model="purchaseForm.PriceDiscount" style="width: 250px;"></el-input>
                    </span>
                </el-table-column>
                <el-table-column label="总重量(斤)" prop="TotalWeight" fixed="right">
                    <span>
                        <el-input v-model="purchaseForm.TotalWeight" style="width: 250px;"></el-input>
                    </span>
                </el-table-column>
            </el-table>
        </el-dialog>
    </div>
</template>
<script setup lang="ts">
import http from '@/http';
import { ref, reactive, inject, onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import type { AxiosStatic } from 'axios';
import {
    Plus,
    Search,
    Delete,
    DocumentChecked,
    Back,
    Warning,
    SuccessFilled,
    Stamp
} from '@element-plus/icons-vue'

//新增弹出层
const dialogTableVisible = ref(false);
//查询条件
const formInline = reactive({
    sheeptypeinfo: "",
    stash: "",
    sdate: "",
    edate: "",
    cottagename: "",
    earbugles: "",
    buyer: "",
    documentnumber: "",
    supplier: ""
});
//采购添加表单
const purchaseForm = reactive({
    PurId: 0,
    DocumentNumber: "",
    PurDate: "",
    AccountingUnit: "",
    SheepTypeInfo: "",
    PruTytpe: "采购单",
    Supplier: "",
    Digest: "",
    Earbugles: "",
    CottageName: "",
    FieldName: "",
    PurSex: "",
    Phase: "",
    Buyer: "",
    Stash: "1",
    GoodName: "",
    Package: "",
    MeasuringUnit: "",
    QuantityNumber: "",
    AveragePrice: "",
    PriceDiscount: "",
    PriceAdjust: "",
    TotalWeight: "",
    CreateBy: "",
    CreateDate: "",
    ExamineType: true
})
//新增行列表
const rowList = ref([]);

const newRow = reactive({
    PurId: 0,
    DocumentNumber: "",
    PurDate: "",
    AccountingUnit: "",
    SheepTypeInfo: "",
    PruTytpe: "",
    Supplier: "",
    Digest: "",
    Earbugles: "",
    CottageName: "",
    FieldName: "",
    PurSex: "",
    Phase: "",
    Buyer: "",
    Stash: "",
    GoodName: "",
    Package: "",
    MeasuringUnit: "",
    QuantityNumber: "",
    AveragePrice: "",
    PriceDiscount: "",
    PriceAdjust: "",
    TotalWeight: "",
    isShow: true
});
//新增行
const addFormInfo = () => {
    purchaseForm.DocumentNumber = "";
    purchaseForm.PurDate = "";
    purchaseForm.AccountingUnit = "";
    purchaseForm.SheepTypeInfo = "";
    purchaseForm.PruTytpe = "采购单";
    purchaseForm.Supplier = "";
    purchaseForm.Digest = "";
    purchaseForm.Earbugles = "";
    purchaseForm.CottageName = "";
    purchaseForm.FieldName = "";
    purchaseForm.PurSex = "";
    purchaseForm.Phase = "";
    purchaseForm.Buyer = "";
    purchaseForm.Stash = "";
    purchaseForm.GoodName = "";
    purchaseForm.Package = "";
    purchaseForm.MeasuringUnit = "";
    purchaseForm.QuantityNumber = "";
    purchaseForm.AveragePrice = "";
    purchaseForm.PriceDiscount = "";
    purchaseForm.PriceAdjust = "";
    purchaseForm.TotalWeight = "";
    rowList.value.push(newRow);
}
//羊只类型集合
const sheeptype = ref([]);
//获取羊只类型
const Getsheeptype = () => {
    http.get("/routechen/api/ReadPurchase/HandleSheepType").then(res => {
        sheeptype.value = res.data;
    });
}
//仓库集合
const StashInfo = ref([]);
//仓库类型
const GetStashInfo = () => {
    http.get("/routechen/api/ReadPurchase/HandleStash").then(res => {
        StashInfo.value = res.data;
    });
}
//栋舍集合
const Cottage = ref([]);
//栋舍下拉方法
const GetCooter = () => {
    http.get("OrganizationRead/api/Cottage/HandleGetCot").then(res => {
        Cottage.value = res.data;
    })
}
//栏位集合
const Field = ref([]);
//栏位下拉方法
const GetField = () => {
    http.get("OrganizationRead/api/Field/HandleGetSheepFarm?Id=" + purchaseForm.CottageName).then(res => {
        Field.value = res.data;
    })
}
//采购员集合
const StaffList = ref([]);
//采购员下拉方法
const GetStaff = () => {
    http.get("Readroute/api/StaffInfo/GetStaff").then(res => {
        StaffList.value = res.data;
    })
}
//核算单元集合
const AccountingList = ref([]);
//核算单元方法
const GetAccounting = () => {
    http.get("routechen/api/ReadPurchase/HandleAccounting").then(res => {
        AccountingList.value = res.data;
    })
}
//核算单元集合
const DigestList = ref([]);
//核算单元方法
const GetDigest = () => {
    http.get("routechen/api/ReadPurchase/HandleDigest").then(res => {
        DigestList.value = res.data;
    })
}
//新增行弹出层
const handleAdd = () => {
    addFormInfo();
    purchaseForm.PurId = 0;
    dialogTableVisible.value = true;
}
//个体采购信息显示
const page = reactive({
    pageIndex: 1,
    pageSize: 15,
    totalCount: 0,
    pageCount: 0
});

const PurList = ref<{}[]>([]);
//个体采购显示
const handleShowPurchase = () => {
    http.get("/routechen/api/ReadPurchase/HandlePurchaseShow", {
        params: {
            pageIndex: page.pageIndex,
            pageSize: page.pageSize,
            Sdate: formInline.sdate,
            Edate: formInline.edate,
            SheeTypeInfo: formInline.sheeptypeinfo,
            Stash: formInline.stash,
            CottageName: formInline.cottagename,
            Earbugles: formInline.earbugles,
            Buyer: formInline.buyer,
            DocumentNumber: formInline.documentnumber,
            Supplier: formInline.supplier
        }
    }).then(res => {
        PurList.value = res.data.datas;
        page.totalCount = res.data.totalCount;
        page.pageCount = res.data.pageCount;
    });
}
const sheepSelList = ref<{
    PurId: any,
    DocumentNumber: any,
    PurDate: any,
    AccountingUnit: any,
    SheepTypeInfo: any,
    PruTytpe: any,
    Supplier: any,
    Digest: any,
    Earbugles: any,
    CottageName: any,
    FieldName: any,
    PurSex: any,
    Phase: any,
    Buyer: any,
    Stash: any,
    GoodName: any,
    Package: any,
    MeasuringUnit: any,
    QuantityNumber: any,
    AveragePrice: any,
    PriceDiscount: any,
    PriceAdjust: any,
    TotalWeight: any,
}[]>([]);
const TagBool = ref(true);
const TagCount = ref(0);
let ids = "";
//获取选中的数据
const handleSelectionChange = (val: PurList | any) => {
    sheepSelList.value = val;
    ids = "";
    val.forEach(item => {
        ids += item.PurId + ",";
    });
    ids = ids.substring(0, ids.length - 1);
    TagCount.value = ids.split(",").length;
    if (ids == "") {
        TagCount.value = 0;
    }
    if (TagCount.value == 0) {
        TagBool.value = true
    }
    else {
        TagBool.value = false
    }
}
//每页显示条数
const handleSizeChange = (val: number) => {
    page.pageSize = val;
    handleShowPurchase();
}
//当前页索引
const handleCurrentChange = (val: number) => {
    page.pageIndex = val;
    handleShowPurchase();
}
//羊只采购添加
const AddPurInfo = () => {
    if (purchaseForm.PurId == 0) {
        http.post("/webroute/api/EntityPurchase/HandleAddPurchase", purchaseForm).then(res => {
            if (res.data > 0) {
                ElMessage({
                    type: 'success',
                    message: '采购成功!',
                    duration: 2000
                })
                NewUpdate();
                handleShowPurchase();
                dialogTableVisible.value = false;
            }
            else if (res.data == -1) {
                ElMessage({
                    type: 'error',
                    message: '采购失败，耳号已存在!',
                    duration: 2000
                })
                return;

            } else {
                ElMessage({
                    type: 'error',
                    message: '采购失败!',
                    duration: 2000
                })
                NewUpdate();
            }
        })
    }
    else {
        http.put("/webroute/api/EntityPurchase/HandleEditPurchase", purchaseForm).then(res => {
            if (res.data > 0) {
                ElMessage({
                    type: 'success',
                    message: '修改采购成功!',
                    duration: 2000
                })
                handleShowPurchase();
                NewUpdate();
                dialogTableVisible.value = false;
            }
            else if (res.data == -1) {
                ElMessage({
                    type: 'error',
                    message: '修改采购失败，耳号不能重复!',
                    duration: 2000
                })
                return;
            }
            else {
                ElMessage({
                    type: 'error',
                    message: '修改采购失败!',
                    duration: 2000
                })
                return;
            }
        })
    }

}
//性别转换
const ChangeSex = () => {
    if (purchaseForm.SheepTypeInfo == "后裔") {
        purchaseForm.PurSex = "";

    }
    else {
        if (purchaseForm.SheepTypeInfo == "种公") {
            purchaseForm.PurSex = "公";
        }
        else if (purchaseForm.SheepTypeInfo == "种母") {
            purchaseForm.PurSex = "母";
        }
        else {
            purchaseForm.PurSex = "";
        }
    }
}
const ChangeSex1 = () => {
    if (purchaseForm.PurSex == "公") {
        purchaseForm.SheepTypeInfo = "种公";
    }
    else if (purchaseForm.PurSex == "母") {
        purchaseForm.SheepTypeInfo = "种母";
    }
    else {
        purchaseForm.PurSex = "";
    }
}


//批量删除
const handleDeleteAll = () => {
    ElMessageBox.confirm(
        '确定要删除当前数据吗?',
        '警告',
        {
            confirmButtonText: '是',
            cancelButtonText: '否',
            type: 'warning',
        }
    ).then(() => {
        http.delete("webroute/api/EntityPurchase/HandleDelAllPurchase?purId=" + sheepSelList.value.map((item) => item.PurId).toString()).then(res => {
            if (res.data > 0) {
                ElMessage({
                    type: "success",
                    message: "删除成功",
                    duration: 2000
                });
                handleShowPurchase();
            }
            else {
                ElMessage({
                    type: "error",
                    message: "删除失败",
                    duration: 2000
                });
                handleShowPurchase();
            }
        })
    })
}


//批量审核
const handleExamine = () => {
    ElMessageBox.confirm(
        '确定要审核通过当前数据吗?',
        '警告',
        {
            confirmButtonText: '是',
            cancelButtonText: '否',
            type: 'warning',
        }
    ).then(() => {
        http.put("webroute/api/EntityPurchase/HandleEmaminePurchase?purId=" + sheepSelList.value.map((item) => item.PurId).toString()).then(res => {
            if (res.data > 0) {
                ElMessage({
                    type: "success",
                    message: "审核通过",
                    duration: 2000
                })
                handleShowPurchase();
            }
            else if (res.data == -1) {
                ElMessage({
                    type: "error",
                    message: "当前数据当中已有审核通过的数据",
                    duration: 2000
                })
                handleShowPurchase();
            }
            else {
                ElMessage({
                    type: "error",
                    message: "审核失败",
                    duration: 2000
                })
                handleShowPurchase();
            }
        })
    })
}
//批量重新审核
const handleNewExamine = () => {
    ElMessageBox.confirm(
        '确定要审核通过当前数据吗?',
        '警告',
        {
            confirmButtonText: '是',
            cancelButtonText: '否',
            type: 'warning',
        }
    ).then(() => {
        http.put("webroute/api/EntityPurchase/HandleNewEmaminePurchase?purId=" + sheepSelList.value.map((item) => item.PurId).toString()).then(res => {
            if (res.data > 0) {
                ElMessage({
                    type: "success",
                    message: "重新审核",
                    duration: 2000
                })
                handleShowPurchase();
            }
            else if (res.data == -1) {
                ElMessage({
                    type: "error",
                    message: "当前数据当中已有重新审核的数据",
                    duration: 2000
                })
                handleShowPurchase();
            }
            else {
                ElMessage({
                    type: "error",
                    message: "重新审核失败",
                    duration: 2000
                })
                handleShowPurchase();
            }
        })
    })
}
const handleDelete = (PurId: number) => {
    ElMessageBox.confirm(
        '确定要删除当前数据吗?',
        '警告',
        {
            confirmButtonText: '是',
            cancelButtonText: '否',
            type: 'warning',
        }
    ).then(() => {
        http.delete("webroute/api/EntityPurchase/HandleDelPurchase?purId=" + PurId).then(res => {
            if (res.data > 0) {
                ElMessage({
                    type: "success",
                    message: "删除成功",
                    duration: 2000
                });
                handleShowPurchase();
            }
            else {
                ElMessage({
                    type: "error",
                    message: "删除失败",
                    duration: 2000
                });
                handleShowPurchase();
            }
        })
    })
}
const handleEdit = (PurId: number) => {
    addFormInfo();
    dialogTableVisible.value = true;
    http.get("routechen/api/ReadPurchase/HandleGetPurchase?purId=" + PurId).then(res => {
        purchaseForm.PurId = res.data.PurId;
        purchaseForm.DocumentNumber = res.data.DocumentNumber;
        purchaseForm.PurDate = res.data.PurDate;
        purchaseForm.AccountingUnit = res.data.AccountingUnit;
        purchaseForm.SheepTypeInfo = res.data.SheepTypeInfo;
        purchaseForm.PruTytpe = res.data.PruTytpe;
        purchaseForm.Supplier = res.data.Supplier;
        purchaseForm.Digest = res.data.Digest;
        purchaseForm.Earbugles = res.data.Earbugles;
        purchaseForm.CottageName = res.data.CottageName;
        purchaseForm.FieldName = res.data.FieldName;
        purchaseForm.PurSex = res.data.PurSex;
        purchaseForm.Phase = res.data.Phase;
        purchaseForm.Buyer = res.data.Buyer;
        purchaseForm.Stash = res.data.Stash;
        purchaseForm.GoodName = res.data.GoodName;
        purchaseForm.Package = res.data.Package;
        purchaseForm.MeasuringUnit = res.data.MeasuringUnit;
        purchaseForm.QuantityNumber = res.data.QuantityNumber;
        purchaseForm.AveragePrice = res.data.AveragePrice;
        purchaseForm.PriceDiscount = res.data.PriceDiscount;
        purchaseForm.PriceAdjust = res.data.PriceAdjust;
        purchaseForm.TotalWeight = res.data.TotalWeight;
        purchaseForm.ExamineType = res.data.ExamineType;
        purchaseForm.CreateBy = res.data.CreateBy;
        purchaseForm.CreateDate = res.data.CreateDate;

        GetField();
        //rowList.value.push(newRow);

    })
}

const SupplierList = ref<{}[]>([]);

const GetSupplier = () => {
    http.get("OrganizationRead/api/Supplier/SleectSupplier").then(res => {
        SupplierList.value = res.data;
    })
}
//关闭弹出层后执行
const NewUpdate = () => {

    rowList.value = [];
    dialogTableVisible.value = false;
}
onMounted(() => {
    Getsheeptype();
    GetStashInfo();
    GetCooter();
    GetStaff();
    GetAccounting();
    GetDigest();
    handleShowPurchase();
    GetSupplier();
})

</script>